<template>
  <van-header title="歌手详情" left-arrow></van-header>
  <div class="loading" v-if="artistSong.length == 0">
    <van-loading size="24px" vertical>加载中...</van-loading>
  </div>
  <div class="section" v-else>
    <div class="sdetail">
      <img :src="artist.picUrl" alt="" />
      <h2 v-html="artist.name"></h2>
      <div class="content">
        <h2 v-html="artist.name"></h2>
        <p class="desc">{{ artist.briefDesc }}</p>
        <van-button icon="plus" color="#ec4141" size="small" round>关注</van-button>
      </div>
    </div>
    <song-list :songs="artistSong" icon></song-list>
  </div>
</template>

<script setup>
import { onBeforeMount, reactive, ref, onMounted } from 'vue';
import VanHeader from '@/components/header/Header.vue';
import SongList from '@/components/songlist/SongList.vue';

import { getArtists } from '@/api/wangyi/singer';
import { createSong } from '@/util';
import { useMyRouters } from '@/router';

const { route } = useMyRouters();
let artist = reactive({
  id: 0,
  name: '',
  picUrl: '',
  briefDesc: ''
});
let artistSong = ref([]);

onBeforeMount(() => {
  console.log('页面参数：' + route.query.id);
  getArtists(route.query.id).then(res => {
    console.log(res);
    const { id, name, picUrl, briefDesc } = res.artist;
    artist.id = id;
    artist.name = name;
    artist.picUrl = picUrl;
    artist.briefDesc = briefDesc;
    let tracks = res.hotSongs;
    let songs = [];
    for (let i = 0; i < tracks.length; i++) {
      songs.push(createSong(tracks[i]));
    }
    console.log(songs);
    artistSong.value = songs;
  });
});
</script>

<style lang="less" scoped>
.section {
  padding: 12px;
}
.sdetail {
  min-height: 285px;
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  font-size: 0;
  img {
    display: block;
    width: 100%;
  }
  .content {
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.375);
    position: absolute;
    top: 0;
    left: 0;
    h2 {
      width: 100%;
      height: 50px;
      color: #fff;
      font-size: 19px;
      // line-height: 23px;
      position: absolute;
      top: 150px;
      left: 15px;
      // z-index: 100;
    }
    .desc {
      color: #fff;
      font-size: 14px;
      line-height: 23px;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      position: absolute;
      top: 180px;
      left: 15px;
    }
    button {
      min-width: 80px;
      padding-right: 8px;
      position: absolute;
      right: 15px;
      bottom: 15px;
    }
  }
}
</style>
